<template>
  <div class="container">
    <div class="top">
      <header class="mask-paper">
        <div class="tool-box"></div>
        <div class="input-box">
          <input type="text" class="search-input" placeholder="搜索" />
          <div class="input-button">
            <div class="close-icon">
              <Close style="width: 1em; height: 1em; margin-right: 8px" />
            </div>
            <div class="search-icon">
              <Search style="width: 1em; height: 1em; margin-right: 8px" />
            </div>
          </div>
        </div>
        <div class="right"></div>
      </header>
    </div>

    <div class="main">
      <div class="side-bar">
        <ul class="channel-list">
          <li :class="{ 'active-channel': route.path === '/' }">
            <a class="link-wrapper">
              <House style="width: 1em; height: 1em; margin-right: 8px" />
              <span class="channel" @click="toDashboard()">发现</span>
            </a>
          </li>
          <li :class="{ 'active-channel': route.path === '/followtrend' }" @click="showInformation = false">
            <Star style="width: 1em; height: 1em; margin-right: 8px" />
            <span class="channel" @click="toTrend()">动态</span>
          </li>
          <li :class="{ 'active-channel': route.path === '/message' }" @click="showInformation = false">
            <Bell style="width: 1em; height: 1em; margin-right: 8px" />
            <span class="channel" @click="toMessage()">消息</span>
          </li>
          <li :class="{ 'active-channel': route.path === '/push' }" @click="showInformation = false">
            <CirclePlus style="width: 1em; height: 1em; margin-right: 8px" />
            <span class="channel" @click="toPush()">发布</span>
          </li>
          <li :class="{ 'active-channel': route.path === '/user' }" @click="showInformation = false">
            <User style="width: 1em; height: 1em; margin-right: 8px" />
            <span class="channel" @click="toUser()">个人</span>
          </li>
        </ul>

        <div class="information-container">
          <!-- 信息面板绑定显示状态 -->
          <div class="information-pad" v-show="showInformation">
            <div class="information-pad">
              <div class="container">
                <div>
                  <div>
                    <div class="group-wrapper">
                      <div class="menu-item hover-effect">
                        <span>关于趣享岛</span>
                        <div class="icon">
                          <ArrowRight style="width: 1em; height: 1em; margin-right: 8px" />
                        </div>
                      </div>
                      <div class="menu-item hover-effect">
                        <span>隐私协议</span>
                        <div class="icon">
                          <ArrowRight style="width: 1em; height: 1em; margin-right: 8px" />
                        </div>
                      </div>
                      <div class="menu-item hover-effect">
                        <span>帮助与客服</span>
                      </div>
                    </div>
                    <div class="divider"></div>
                  </div>
                  <div>
                    <div class="group-wrapper">
                      <div class="group-header">访问方式</div>
                      <div class="menu-item hover-effect">
                        <span>键盘快捷键</span>
                        <div class="icon">
                          <Search style="width: 1em; height: 1em; margin-right: 8px" />
                        </div>
                      </div>
                      <div class="menu-item hover-effect">
                        <span>添加到桌面</span>
                        <div class="icon">
                          <ArrowRight style="width: 1em; height: 1em; margin-right: 8px" />
                        </div>
                      </div>
                      <div class="menu-item hover-effect">
                        <span>小窗模式</span>
                      </div>
                    </div>
                    <div class="divider"></div>
                  </div>
                  <div>
                    <div class="group-wrapper">
                      <div class="group-header">设置</div>
                      <div class="menu-item hover-effect">
                        <span>深色模式</span>
                        <div class="multistage-toggle component">
                          <button class="toggle-item active">
                            <div class="icon-wrapper">
                              <Sunny style="width: 1em; height: 1em" />
                            </div>
                          </button>
                          <button class="toggle-item">
                            <div class="icon-wrapper">
                              <Moon style="width: 1em; height: 1em" />
                            </div>
                          </button>
                        </div>
                      </div>
                      <div class="menu-item hover-effect">
                        <span>退出登录</span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <!-- 更多按钮添加点击事件 -->
          <div class="information-wrapper" @click="toggleInformation">
            <More style="width: 1em; height: 1em; margin-right: 8px" />
            <span class="channel">更多</span>
          </div>
        </div>
      </div>

      <div class="main-content with-side-bar">
        <router-view />
      </div>
    </div>

    <Login v-show="c" @click-child="close"></Login>
  </div>
</template>

<script lang="ts" setup>
import {
  Search,
  Sunny,
  Moon,
  Close,
  House,
  Star,
  Bell,
  User,
  ArrowRight,
  More,
  CirclePlus,
} from "@element-plus/icons-vue";
import { useRouter, useRoute } from "vue-router";
import Login from "@/pages/login.vue";
import { ref } from "vue";

const route = useRoute();
const router = useRouter();

const c = ref(true);
const showInformation = ref(false); // 显示状态

// 添加隐藏逻辑
const toDashboard = () => {
  router.push({ path: "/" });
  showInformation.value = false;
};

const toTrend = () => {
  router.push({ path: "/followtrend" });
  showInformation.value = false;
};

const toMessage = () => {
  router.push({ path: "/message" });
  showInformation.value = false;
};

const toPush = () => {
  router.push({ path: "/push" });
  showInformation.value = false;
};

const toUser = () => {
  router.push({ path: "/user" });
  showInformation.value = false;
};

// 切换方法
const toggleInformation = () => {
  showInformation.value = !showInformation.value;
};


const close = (val: boolean) => {
  console.log(val);
  c.value = val;
};
</script>

<style lang="less" scoped>
.container {
  max-width: 1728px;
  background-color: #fff;
  margin: 0 auto;

  .top {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100vw;
    height: 72px;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10;
    align-items: center;
    background: #fff;

    header {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      max-width: 1728px;
      height: 72px;
      padding: 0 16px 0 24px;
      z-index: 10;

      .tool-box {
        width: 24px;
        height: 70px;
        position: absolute;
        left: 0;
        top: 0;
      }

      .input-box {
        height: 40px;
        position: fixed;
        left: 50%;
        transform: translate(-50%);

        @media screen and (max-width: 695px) {
          display: none;
        }

        @media screen and (min-width: 960px) and (max-width: 1191px) {
          width: calc(-36px + 50vw);
        }

        @media screen and (min-width: 1192px) and (max-width: 1423px) {
          width: calc(-33.6px + 40vw);
        }

        @media screen and (min-width: 1424px) and (max-width: 1727px) {
          width: calc(-42.66667px + 33.33333vw);
        }

        @media screen and (min-width: 1728px) {
          width: 533.33333px;
        }

        .search-input {
          padding: 0 84px 0 16px;
          width: 100%;
          height: 100%;
          font-size: 16px;
          line-height: 120%;
          color: #333;
          caret-color: #ff2442;
          background: rgba(0, 0, 0, 0.03);
          border-radius: 999px;
        }

        .input-button {
          position: absolute;
          right: 0;
          top: 0;
          display: flex;
          align-items: center;
          justify-content: center;
          height: 100%;
          color: rgba(51, 51, 51, 0.8);

          .close-icon .search-icon {
            width: 40px;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: rgba(51, 51, 51, 0.8);
          }
        }
      }
    }
  }

  .main {
    display: flex;

    .side-bar {
      @media screen and (max-width: 695px) {
        display: none;
      }

      @media screen and (min-width: 696px) and (max-width: 959px) {
        display: none;
      }

      @media screen and (min-width: 960px) and (max-width: 1191px) {
        width: calc(-18px + 25vw);
        margin-left: 12px;
      }

      @media screen and (min-width: 1192px) and (max-width: 1423px) {
        width: calc(-16.8px + 20vw);
        margin-left: 12px;
      }

      @media screen and (min-width: 1424px) and (max-width: 1727px) {
        width: calc(-21.33333px + 16.66667vw);
        margin-left: 16px;
      }

      @media screen and (min-width: 1728px) {
        width: 266.66667px;
        margin-left: 16px;
      }

      height: calc(100vh - 72px);
      overflow-y: scroll;
      background-color: #fff;
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
      padding-top: 16px;
      margin-top: 72px;
      position: fixed;
      overflow: visible;

      .channel-list {
        min-height: auto;
        -webkit-user-select: none;
        user-select: none;

        .active-channel {
          background-color: rgba(0, 0, 0, 0.03);
          border-radius: 999px;
          color: #333;
        }

        li {
          padding-left: 16px;
          min-height: 48px;
          display: flex;
          align-items: center;
          cursor: pointer;
          margin-bottom: 8px;
          color: rgba(51, 51, 51, 0.6);

          .link-wrapper {
            display: flex;
            width: 100%;
            height: 48px;
            align-items: center;
          }
        }

        .channel {
          font-size: 16px;
          font-weight: 600;
          margin-left: 12px;
          color: #333;
        }
      }

      .information-container {
        display: inline-block;
        width: 100%;
        color: #333;
        font-size: 16px;
        position: absolute;
        bottom: 0;

        .information-pad {
          z-index: 16;
          margin-bottom: 4px;
          width: 100%;

          .container {
            width: 100%;
            background: #fff;
            box-shadow:
              0 4px 32px 0 rgba(0, 0, 0, 0.08),
              0 1px 4px 0 rgba(0, 0, 0, 0.04);
            border-radius: 12px;

            .divider {
              margin: 0px 12px;
              list-style: none;
              height: 0;
              border: 1px solid rgba(0, 0, 0, 0.08);
              border-width: 1px 0 0;
            }

            .group-wrapper {
              padding: 4px;

              .group-header {
                display: flex;
                align-items: center;
                padding: 0 12px;
                font-weight: 400;
                height: 32px;
                color: rgba(51, 51, 51, 0.6);
                font-size: 12px;
              }

              .menu-item {
                height: 40px;
                color: rgba(51, 51, 51, 0.8);
                font-size: 16px;
                border-radius: 8px;
                display: flex;
                align-items: center;
                padding: 0 12px;
                font-weight: 400;

                .icon {
                  color: rgba(51, 51, 51, 0.3);
                  margin-left: auto;
                }

                .component {
                  margin-left: auto;
                }

                .multistage-toggle {
                  position: relative;
                  background: rgba(0, 0, 0, 0.03);
                  display: flex();
                  padding: 2px;
                  border-radius: 999px;
                  cursor: pointer;

                  .active {
                    background: #fff;
                    box-shadow:
                      0 2px 8px 0 rgba(0, 0, 0, 0.04),
                      0 1px 2px 0 rgba(0, 0, 0, 0.02);
                    color: #333;
                  }

                  .toggle-item {
                    border-radius: 999px;
                    background: transparent;
                    color: rgba(51, 51, 51, 0.6);

                    .icon-wrapper {
                      width: 24px;
                      height: 24px;
                      display: flex;
                      align-items: center;
                      justify-content: center;
                      cursor: pointer;
                    }
                  }
                }
              }
            }
          }
        }

        .information-wrapper {
          -webkit-user-select: none;
          user-select: none;
          cursor: pointer;
          position: relative;
          margin-bottom: 20px;
          height: 48px;
          width: 100%;
          display: flex;
          font-weight: 600;
          align-items: center;
          border-radius: 999px;
        }
      }
    }

    .main-content {
      width: 100%;
    }

    .main-content {
      @media screen and (min-width: 960px) and (max-width: 1191px) {
        padding-left: calc(-6px + 25vw);
      }

      @media screen and (min-width: 1192px) and (max-width: 1423px) {
        padding-left: calc(-4.8px + 20vw);
      }

      @media screen and (min-width: 1424px) and (max-width: 1727px) {
        padding-left: calc(-5.33333px + 16.66667vw);
      }

      @media screen and (min-width: 1728px) {
        padding-left: 282.66667px;
      }
    }
  }
}

.information-pad {
  transition: all 0.3s ease;
  transform-origin: bottom;
}

.information-wrapper {
  cursor: pointer;
  transition: background-color 0.2s;

  &:hover {
    background-color: rgba(0, 0, 0, 0.03);
  }
}
</style>